package com.fhao.blog.mapper;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

import static com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat.UUID;

public class MD5Utils {
    public static void main(String[] args) {
        //"123456"是明文,md5DigestAsHex方法的作用是将明文加密成 16 进制的密文,
        // 只要明文相同,通过 md5DigestAsHex 方法加密产生的密文 相同.
        System.out.println(DigestUtils.md5DigestAsHex("123456".getBytes()));
        System.out.println(DigestUtils.md5DigestAsHex("123456".getBytes()));
        System.out.println(DigestUtils.md5DigestAsHex("123456".getBytes()));
        //randomUUID()方法的作用是产生随机的字符串, 用来作为随机的盐值.
        //randomUUID()产生的随机字符串包括 四个 "-",需要去掉 "-"才能作为随机盐值.
        System.out.println(java.util.UUID.randomUUID());
        System.out.println(java.util.UUID.randomUUID());
        System.out.println(java.util.UUID.randomUUID().toString().replace("-",""));
        System.out.println(java.util.UUID.randomUUID().toString().replace("-",""));
        String random = java.util.UUID.randomUUID().toString().replace("-","");
        //明文+盐值
        String password = "123456"+random;
        System.out.println(password);
        System.out.println(DigestUtils.md5DigestAsHex(password.getBytes()));
    }
}
















